package com.ruoyi.project.para.paeaParaCalendar.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.para.paeaParaCalendar.domain.PaeaParaCalendar;
import com.ruoyi.project.para.paeaParaCalendar.service.IPaeaParaCalendarService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作日历Controller
 *
 * @author ruoyi
 * @date 2020-03-12
 */
@Controller
@RequestMapping("/para/paeaParaCalendar")
public class PaeaParaCalendarController extends BaseController
{
    private String prefix = "para/paeaParaCalendar";

    @Autowired
    private IPaeaParaCalendarService paeaParaCalendarService;

    @RequiresPermissions("para:paeaParaCalendar:view")
    @GetMapping()
    public String calendar()
    {
//        return prefix + "/paeaParaCalendar";
        return prefix + "/paeaParaCalendar";
    }

    /**
     * 查询工作日历列表
     */
    @RequiresPermissions("para:paeaParaCalendar:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaParaCalendar paeaParaCalendar)
    {
        startPage();
        List<PaeaParaCalendar> list = paeaParaCalendarService.selectPaeaParaCalendarList(paeaParaCalendar);
        return getDataTable(list);
    }

    /**
     * 查询选择年份的工作日历情况
     */
    @RequiresPermissions("para:paeaParaCalendar:view")
    @GetMapping("/list/{year}")
    @ResponseBody
    public AjaxResult listYear(@PathVariable("year") String year)
    {
        List<PaeaParaCalendar> list = paeaParaCalendarService.list(new QueryWrapper<PaeaParaCalendar>().eq("code",year));
        return AjaxResult.success(list);
    }

    /**
     * 导出工作日历列表
     */
    @RequiresPermissions("para:paeaParaCalendar:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaParaCalendar paeaParaCalendar)
    {
        List<PaeaParaCalendar> list = paeaParaCalendarService.selectPaeaParaCalendarList(paeaParaCalendar);
        ExcelUtil<PaeaParaCalendar> util = new ExcelUtil<PaeaParaCalendar>(PaeaParaCalendar.class);
        return util.exportExcel(list, "paeaParaCalendar");
    }

    /**
     * 新增工作日历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工作日历
     */
    @RequiresPermissions("para:paeaParaCalendar:add")
    @Log(title = "工作日历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaParaCalendar paeaParaCalendar)
    {
        return toAjax(paeaParaCalendarService.insertPaeaParaCalendar(paeaParaCalendar));
    }

    /**
     * 修改工作日历
     */
    @GetMapping("/edit/{description}")
    public String edit(@PathVariable("description") String description, ModelMap mmap)
    {
        PaeaParaCalendar paeaParaCalendar = paeaParaCalendarService.selectPaeaParaCalendarById(description);
        mmap.put("paeaParaCalendar", paeaParaCalendar);
        return prefix + "/edit";
    }

    /**
     * 修改保存工作日历
     */
    @RequiresPermissions("para:paeaParaCalendar:edit")
    @Log(title = "工作日历", businessType = BusinessType.UPDATE, isSaveResponseData = false)
    @PostMapping("/edit/{year}")
    @ResponseBody
    public AjaxResult editSave(@PathVariable("year") String year, @RequestParam(value = "dates")String dates)
    {
        return AjaxResult.success(paeaParaCalendarService.batchUpdatePaeaParaCalendar(year,dates));
    }

    /**
     * 删除工作日历
     */
    @RequiresPermissions("para:paeaParaCalendar:remove")
    @Log(title = "工作日历", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaParaCalendarService.deletePaeaParaCalendarByIds(ids));
    }

    /**
     * 初始化当前年工作日历
     */
    @RequiresPermissions("para:paeaParaCalendar:init")
    @Log(title = "工作日历", businessType = BusinessType.CLEAN, isSaveResponseData = false)
    @GetMapping( "/init/{year}")
    @ResponseBody
    public AjaxResult init(@PathVariable("year") String year)
    {
        return AjaxResult.success(paeaParaCalendarService.initPaeaParaCalendar(year));
    }
}
